﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core
{
    public static partial class contest
    {
        public static dynamic showContestList(bool god, int start, int limit)
        {
            var sql = new Sql.SqlDataContext();
            var total = sql.Contest.Count(row => !row.disabled || god);
            IQueryable result;
            result = (from c in sql.Contest
                    where (!c.disabled || god)
                    orderby c.startTime
                    select new
                    {
                        cid = c.cid,
                        title = c.title,
                        start_time = functional.toTimeString(c.startTime),
                        over_time = functional.toTimeString(c.overTime),
                        is_public = c.is_public,
                        description = c.description,
                        opening = c.overTime < DateTime.Now ? 2 : (c.startTime <= DateTime.Now && c.overTime >= DateTime.Now) ? 1 : 0
                    }).Skip(start).Take(limit);
            return new
            {
                result,
                total,
                suceess = true
            };
        }
    }
}
